package com.ruiyian.bridge.project.controller;

import com.ruiyian.bridge.project.domain.BridgeInfo;
import com.ruiyian.bridge.project.service.BridgeInfoService;
import com.ruiyian.common.annotation.Log;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.enums.BusinessType;
import com.ruiyian.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 桥梁基本信息Controller
 *
 * @author ruiyian
 * @date 2022-01-19
 */
@RestController
@RequestMapping("/bridge/project/info")
public class BridgeInfoController extends BaseController
{
    @Autowired
    private BridgeInfoService tBridgeInfoService;

    /**
     * 查询桥梁基本信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BridgeInfo bridgeInfo)
    {
        startPage();
        List<BridgeInfo> list = tBridgeInfoService.selectTBridgeInfoList(bridgeInfo);
        return getDataTable(list);
    }


    @GetMapping("/listAll")
    public AjaxResult listAll(BridgeInfo bridgeInfo)
    {
        List<BridgeInfo> list = tBridgeInfoService.selectTBridgeInfoList(bridgeInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出桥梁基本信息列表
     */
    @Log(title = "桥梁基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BridgeInfo bridgeInfo)
    {
        List<BridgeInfo> list = tBridgeInfoService.selectTBridgeInfoList(bridgeInfo);
        ExcelUtil<BridgeInfo> util = new ExcelUtil<BridgeInfo>(BridgeInfo.class);
        try {
            util.exportExcel(response, list, "桥梁基本信息数据");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取桥梁基本信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tBridgeInfoService.selectTBridgeInfoById(id));
    }

    /**
     * 新增桥梁基本信息
     */
    @Log(title = "桥梁基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BridgeInfo bridgeInfo)
    {
        return toAjax(tBridgeInfoService.insertTBridgeInfo(bridgeInfo));
    }

    /**
     * 修改桥梁基本信息
     */
    @Log(title = "桥梁基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BridgeInfo bridgeInfo)
    {
        return toAjax(tBridgeInfoService.updateTBridgeInfo(bridgeInfo));
    }

    /**
     * 删除桥梁基本信息
     */
    @Log(title = "桥梁基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBridgeInfoService.deleteTBridgeInfoByIds(ids));
    }
}
